package com.reebake.ideal.security.handler;

import com.reebake.ideal.security.code.CodeAuthenticationToken;
import com.reebake.ideal.security.core.AuthenticationFactorConvertor;
import com.reebake.ideal.security.entity.CodeAuthenticationFactor;
import org.springframework.security.core.Authentication;

public class CodeAuthenticationFactorConvertor implements AuthenticationFactorConvertor<CodeAuthenticationFactor> {
    @Override
    public Class<CodeAuthenticationFactor> getFactorType() {
        return CodeAuthenticationFactor.class;
    }

    @Override
    public Authentication convert(CodeAuthenticationFactor authenticationFactor) {
        CodeAuthenticationToken authenticationToken = new CodeAuthenticationToken(authenticationFactor.getCredential());
        authenticationToken.setCaptcha(authenticationFactor.getCaptcha());
        return authenticationToken;
    }
}
